package webgamemaker.Editor;

import java.util.ArrayList;

public class HistoryManager 
{
	public ArrayList<HistoryAction> listAction;
	public int pos;
	
	public HistoryManager()
	{
		listAction = new ArrayList<HistoryAction>();
		pos = -1;
	}
	
	public void makeAction(HistoryAction action)
	{
		while(listAction.size() > pos+1)
			listAction.remove(listAction.size()-1);
		listAction.add(action);
		redo();
	}
	
	public void undo()
	{
		if(pos >= 0)
			listAction.get(pos--).undo();
	}
	
	public void redo()
	{
		if(pos < listAction.size()-1)
			listAction.get(++pos).redo();
	}
	
	public interface HistoryAction
	{
		public void undo();
		public void redo();
	}
}
